<?php
require_once ( PATH_DATABASE.'class.dbcontrol.inc.php' );
class Db_Packet extends db {
	public function __construct(){
//		$this->setTable('ams_packet');
	}
	public function doInsertPacket($aData){
		parent::StartTrans();
                parent::insert( 'ams_packet', Array(
        						'name' => $aData[packet_name],
						        'description' =>$aData[packet_description],
						        'image' =>$aData[packet_image],
        						'download_items' =>$aData[packet_download_items],
        						'period'=>$aData[packet_period],
        						'price' =>$aData[packet_price],
        						'status' =>$aData[packet_status],
                  ), false,__LINE__, __FILE__ );
                $id = parent::get_last_insert_id();
                parent::Commit();
                return $id;
	}
	public function doListPacket(){
		$sSql = "SELECT * FROM ams_packet WHERE 1=1";
		return parent::execute_query($sSql, __LINE__, __FILE__);
	}
	public function doDeletePacketById($id){
		$sSql = "DELETE FROM `ams_packet` WHERE `id` = '$id'"; 			 
		parent::execute_query($sSql, __LINE__, __FILE__);
		return true;
	}
	public function doUpdatePacketById($aData, $id){
		parent::StartTrans();     
                parent::update( 'ams_packet', Array(
                                                                'name' => $aData[packet_name],
                                                                'description' =>$aData[packet_description],
                                                                'image' =>$aData[packet_image],
                                                                'download_items' =>$aData[packet_download_items],
                                                                'period'=>$aData[packet_period],
                                                                'price' =>$aData[packet_price],
                                                                'status' =>$aData[packet_status],
                      ),Array('id' => $id),__LINE__,__FILE__);
		parent::Commit();
		return true;
	}
	public function doGetPacketById($id){
		$sSql = "SELECT * FROM ams_packet WHERE id='$id'";
		return parent::execute_query($sSql, __LINE__, __FILE__);
	}
        public function doListPacketActive(){
		$sSql = "SELECT * FROM ams_packet WHERE status = 1";
		return parent::execute_query($sSql, __LINE__, __FILE__);
	}
        public function doInsertTrans($aData){
		parent::StartTrans();
                parent::insert( 'ams_transactions', $aData, false,__LINE__, __FILE__ );
                $id = parent::get_last_insert_id();
                parent::Commit();
                return $id;
	}
}